package com.faxsun.web.endpoint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.faxsun.core.service.LiveInteractionService;
import com.faxsun.pojos.LiveInteractionStats;
import com.faxsun.web.utils.Response;

@Controller
@RequestMapping("/api/v1/live")
public class LiveInteractionStatsEndpoint {
	private static final Logger logger = LoggerFactory
			.getLogger(LiveInteractionStatsEndpoint.class);
	@Autowired
	LiveInteractionService liveInteractionService;

	@RequestMapping(value = "/active/stats/{liveId}", method = RequestMethod.GET)
	@ResponseBody
	public Response getInteractionStats(@PathVariable("liveId") long liveId,
			@RequestParam("q") String q) {
		try {
			logger.info("q:" + q);
			LiveInteractionStats data = liveInteractionService
					.getLiveInteractionStats(liveId);
			return Response.build("获取互动统计信息成功！", "success", data);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return Response.build("获取互动统计信息失败！", "failure", null);
		}
	}
}
